package com.sxt.opd.controller;



import com.sxt.opd.vo.RecordVo;
import com.sxt.springcloud.opd.RecordClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.WebRequest;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2020-01-31
 */
@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private RecordClientService recordClientService;

    /**
     * 前台传日期，后台Date接值类型转换错误
     * @param binder
     * @param request
     */
    @InitBinder
    public void InitBinder(WebDataBinder binder, WebRequest request)
    {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor editor = new CustomDateEditor(df,true);//参数为true表示允许为空值
        binder.registerCustomEditor(Date.class, editor);
    }

    /**
     * 查询
     */
    @RequestMapping("loadAllRecord")
    public DataGridView loadAllRecord(RecordVo recordVo) {
        return this.recordClientService.loadAllRecord(recordVo);
    }

    /**
     * 添加
     */
    @RequestMapping("addRecord")
    public ResultObj addRecord(RecordVo recordVo) {
        return this.recordClientService.addRecord(recordVo);
    }

    /**
     * 修改
     */
    @RequestMapping("updateRecord")
    public ResultObj updateRecord(RecordVo recordVo) {
        return this.recordClientService.updateRecord(recordVo);
    }

    /**
     * 删除
     */
    @RequestMapping("deleteRecord")
    public ResultObj deleteRecord(Integer id) {
        return this.recordClientService.deleteRecord(id);
    }

}

